package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.CreateLive;

import android.app.AlertDialog;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.Adapter.MemberManageAdapter;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.ItemBean.Member;

import java.util.ArrayList;
import java.util.List;

public class MemberManageFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;
    View view;
    ImageView iv_back;
    Button btn_slient;
    RecyclerView rv_members;

    private List<Member> memberList;


    public MemberManageFragment() {
    }
    public static MemberManageFragment newInstance(String param1, String param2) {
        MemberManageFragment fragment = new MemberManageFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.course_member_manage_fragment, container, false);
        //返回监听
        iv_back = view.findViewById(R.id.back);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handleBackPressed();
            }
        });
        //全员静音
        btn_slient = view.findViewById(R.id.btn_slient);
        btn_slient.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater inflater = LayoutInflater.from(v.getContext());
                View dialogView = inflater.inflate(R.layout.pop_up_windows, null);
                AlertDialog.Builder alert_builder = new AlertDialog.Builder(v.getContext());
                alert_builder.setView(dialogView);
                AlertDialog dialog = alert_builder.create();
                Button btn_cancel = dialogView.findViewById(R.id.btn_cancel);
                Button btn_confirm = dialogView.findViewById(R.id.btn_confirm);
                CheckBox cb_allow_unmute = dialogView.findViewById(R.id.cb_allow_unmute);

                cb_allow_unmute.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });

                // 设置按钮点击事件
                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 确定操作
                        dialog.dismiss();
                    }
                });

                btn_confirm.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 取消操作
                        dialog.dismiss();
                    }
                });
                dialog.show();


            }
        });

        //
        rv_members = view.findViewById(R.id.rv_members);
        InitData();
        rv_members.setLayoutManager(new LinearLayoutManager(getActivity()));
        rv_members.setAdapter(new MemberManageAdapter(memberList));

        return view;
    }

    private void InitData() {
        memberList = new ArrayList<>();
        memberList.add(new Member(R.drawable.example_face, "张老师","(主持人,我)"));
        memberList.add(new Member(R.drawable.example_face, "小张","(成员)"));
        memberList.add(new Member(R.drawable.example_face, "小王","(成员)"));
        memberList.add(new Member(R.drawable.example_face, "小李","(成员)"));
    }
}